package com.zimin.cloud.web.controller.wiki;

import com.zimin.cloud.mine.pojo.wiki.business.DocBO;
import com.zimin.cloud.wiki.api.IDocFeign;
import com.zimin.shared.annotation.RedisLock;
import com.zimin.shared.pojo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

/**
 * @author zimin
 * @since 2021/12/22 4:52 下午
 */
@RestController
@RequestMapping("/web/wiki/doc")
@Slf4j
public class WebWikiDocController {

    @Autowired
    private IDocFeign docFeign;

    @GetMapping
    public Mono<Result> docList(DocBO docBO) {
        Result result = docFeign.docList(docBO);
        return Mono.just(result);
    }

    @GetMapping("/all")
    public Mono<Result> all(DocBO docBO) {
        Result result = docFeign.docAll(docBO);
        return Mono.just(result);
    }

    @PostMapping
    @RedisLock
    public Mono<Result> saveDoc(@RequestBody DocBO docBO) {
        Result result = docFeign.saveDoc(docBO);
        return Mono.just(result);
    }

    @PutMapping
    @RedisLock
    public Mono<Result> updateDoc(@RequestBody DocBO docBO) {
        Result result = docFeign.updateDoc(docBO);
        return Mono.just(result);
    }

    @DeleteMapping("/{ids}")
    public Mono<Result> removeById(@PathVariable(name = "ids") String ids) {
        Result result = docFeign.removeDocById(ids);
        return Mono.just(result);
    }

    @GetMapping("/{id}")
    public Mono<Result> getDocContent(@PathVariable(name = "id") String id) {
        Result result = docFeign.getDocContent(id);
        return Mono.just(result);
    }

}
